﻿'use strict';

var zxcv = {
    raw: {
        timestamp: 0,
        frame: 0,
        fps: 0,
        assetBox: null,
        graphics: null,
        audio: null,
        input: null,

        start: function (settings, systems) {
            var raw = zxcv.raw;

            raw.update    = settings.update || function () {};
            raw.draw      = settings.draw   || function () {};
            raw.timestamp = zxcv.now();
            raw.fps       = settings.fps;

            raw.assetBox  = systems.assetBox;
            raw.graphics  = systems.graphics;
            raw.audio     = systems.audio;
            raw.input     = systems.input;
            raw.renderer  = systems.renderer;

            zxcv.e = {
                name: 'root',
                transform: new zxcv.TransformNode(),
                visual: new zxcv.VisualNode(),
            };

            if (settings.start)
                settings.start();

            zxcv.load('../js/glsl/geometry-vs.glsl');
            zxcv.load('../js/glsl/geometry-fs.glsl');
        },
        tick: function () {
            var raw = zxcv.raw,
                now = zxcv.now(),
                elapsedTime = now - raw.timestamp,
                dt = elapsedTime * 0.001,
                frame = raw.frame;

            raw.update();

            raw.graphics.begin();
            raw.draw(raw.renderer);
            raw.graphics.end();

            raw.timestamp = now;
            raw.frame += 1;
        },
        update: null,
        draw: null,
    },
};